﻿using System;
using System.ComponentModel.DataAnnotations;

namespace Sita.Entities
{
    //[MetadataType(typeof(Metadata.User))]
    public partial class User
    {
        public string FullName
        {
            get { return this.Firstname + " " + this.Lastname; }
        }

        public override string ToString()
        {
            string ObjectString;
            System.Reflection.PropertyInfo[] ObjectProperties;
            Type ObjectType;

            ObjectType = this.GetType();
            ObjectProperties = ObjectType.GetProperties();

            ObjectString = "::[Entity " + ObjectType.Name + "]::";

            for (int i = 0; i < ObjectProperties.Length; i++)
            {
                ObjectString += " | " + ObjectProperties[i].Name + " = " + ObjectProperties[i].GetValue(this, new object[] { });
            }

            return ObjectString;
        }

        public bool IsOnline(int ExpirationMinutes)
        {
            if (!LastPostBack.HasValue)
            {
                return false;
            }

            return DateTime.Now < LastPostBack.Value.AddMinutes(ExpirationMinutes);
        }

    }
}